<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <!-- 
        100元买2元的铅笔，5元的铅笔盒，10元的文件夹，15元的彩笔，刚好花光，
        每样物品必须有一种，一共有多少种可能性？
     -->
</head>

<body>

</body>
<script>
    let money = 100;
    let arr = [2, 5, 10, 15];
    console.log(possibleCount(money, arr));

    function possibleCount(money, arr) {
        let len = arr.length;
        arr.sort(function (a, b) {
            return b - a;
        }); //对数组降序排列[15，10，5，2]
        let dp = [];
        for (let i = 0; i < money + 1; i++) {
            dp[i] = 0;
        }
        dp[0] = 1;

        for (let i = 0; i < arr.length; i++) {
            for (let j = money; j >= arr[i]; j--) {
                dp[j] += dp[j - arr[i]];
            }
        }
        console.log(dp);
        return dp[money];
    }
</script>

</html>